from typing import List


class Solution:
    def maxSubArray(self, nums: List[int]) -> int:
        n = len(nums)
        current_sum = max_sum = nums[0]  # 初始化

        for i in range(1, n):
            current_sum = max(nums[i], current_sum + nums[i])  # 决定是否延续子数组或重新开始
            max_sum = max(max_sum, current_sum)  # 更新全局最大值

        return max_sum